# -*- coding: utf-8 -*- 
# @project : 《Atcoder》
# @Author : created by bensonrachel on 2021/12/31
# @File : 3. 无重复字符的最长子串.py

class Solution:
    def lengthOfLongestSubstring(self, s: str) -> int:
        left = 0
        right = 0
        ans = 0
        d = dict()
        size = len(s)
        while(right<size):
            if s[right] in d and d[s[right]] >= left:
                left = d[s[right]] + 1
            else:
                ans = max(ans,right-left+1)
            d[s[right]] = right
            right += 1
        return ans

